package com.meng.mini.spring.core;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.net.URL;
import java.util.Iterator;

/**
 * @author Meng Xu
 * @version 1.0.0
 * @date 2024-01-16 10:08
 **/
public class ClassPathXmlResource implements Resource {

    Document document;

    Element rootElement;

    Iterator<Element> elementIterable;

    public ClassPathXmlResource(String fileName){
        SAXReader saxReader = new SAXReader();

        URL xmlPath = this.getClass().getClassLoader().getResource(fileName);
        //价格配置文件装载进来，生成迭代器，可以用于遍历
        try {
            this.document = saxReader.read(xmlPath);
            this.rootElement = document.getRootElement();
            this.elementIterable = this.rootElement.elementIterator();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }


    @Override
    public boolean hasNext() {
        return false;
    }

    @Override
    public Object next() {
        return null;
    }
}
